home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Book Chapters / 13 - PowerPC / Optimize 3 / Main.c < prev    next >
C/C++ Source or Header  |  1995-03-05  |  4KB  |  174 lines

  1. /*********************/
  2. /*     MAIN.C        */
  3. /*********************/
  4. //
  5. // This file contains all of the initialization and
  6. // setup code needed to do the screen blit.
  7. //
  8.  
  9.  
  10. /****************************/
  11. /*    EXTERNALS             */
  12. /****************************/
  13.  
  14. #include <qdoffscreen.h>
  15.  
  16.  
  17. /****************************/
  18. /*    PROTOTYPES            */
  19. /****************************/
  20.  
  21. static void ToolBoxInit(void);
  22. static void HideMenuBar(void);
  23. static void InitScreen(void);
  24. static void InitDrawBuffer(void);
  25. static void ShowMenuBar(void);
  26. void main(void);
  27.  
  28. void ProfileIt(void);
  29.  
  30.  
  31. /****************************/
  32. /*    CONSTANTS             */
  33. /****************************/
  34.  
  35.  
  36. /****************************/
  37. /*    VARIABLES             */
  38. /****************************/
  39.  
  40. Ptr            gScreenAddr,gDrawBufferPtr;
  41. long        gScreenRowBytes;
  42.  
  43. short        gOldMBarHeight;
  44. RgnHandle    gMBarRgn;
  45.  
  46.  
  47.  
  48. /************* TOOLBOX INIT  ***************/
  49. //
  50. // Initialize toolbox stuff.
  51. //
  52.  
  53. static void ToolBoxInit(void)
  54. {
  55.      MaxApplZone();
  56.     InitGraf(&qd.thePort);
  57.     FlushEvents ( everyEvent, 0);
  58.     InitFonts();
  59.     InitWindows();
  60.     InitDialogs(nil);
  61.     InitCursor();
  62.     InitMenus();
  63.     TEInit();    
  64. }
  65.  
  66.  
  67. /**************** HIDE MENU BAR *******************/
  68. //
  69. // Hides the menu bar
  70. //
  71.  
  72. static void HideMenuBar(void)
  73. {
  74. Rect            mBarRect;
  75.  
  76.             /* GET RID OF THE MENU BAR */
  77.                     
  78.     gOldMBarHeight = GetMBarHeight();
  79.     LMSetMBarHeight(0);                                    // make the Menu Bar's height zero
  80.     SetRect(&mBarRect, qd.screenBits.bounds.left, qd.screenBits.bounds.top,
  81.                 qd.screenBits.bounds.right, qd.screenBits.bounds.top + gOldMBarHeight);
  82.     gMBarRgn = NewRgn();
  83.     RectRgn(gMBarRgn, &mBarRect);
  84.     UnionRgn(LMGetGrayRgn(), gMBarRgn, LMGetGrayRgn());    // tell the desktop it covers the menu bar
  85.  
  86.     PaintOne(nil, gMBarRgn);                            // redraw desktop
  87. }
  88.  
  89.  
  90. /******************** SHOW MENU BAR ******************/
  91. //
  92. // Restores the menu bar when we are done
  93. //
  94.  
  95. static void ShowMenuBar(void)
  96. {
  97.     LMSetMBarHeight(gOldMBarHeight);                    // make the menu bar's height normal
  98.     DiffRgn(LMGetGrayRgn(), gMBarRgn, LMGetGrayRgn());    // remove the menu bar from the desktop
  99.     DisposeRgn(gMBarRgn);
  100. }
  101.  
  102.  
  103. /******************* INIT SCREEN ***********************/
  104. //
  105. // Prepares screen for full-screen drawing.
  106. // Hides the menu bar, then creates a giant
  107. // window to cover the entire desktop.
  108. //
  109.  
  110. static void InitScreen(void)
  111. {
  112. Rect            screenRect;
  113. GDHandle        mainScreen;
  114. PixMapHandle    mainScreenPixMap;
  115. WindowPtr        bigWindow;
  116.  
  117.     HideMenuBar();                                                    // hide the menu bar
  118.  
  119.  
  120.             /* GET ADDR & ROWBYTES */
  121.  
  122.     mainScreen = GetMainDevice();                                    // get screen device
  123.     mainScreenPixMap = (**mainScreen).gdPMap;                        // get screen pixMap
  124.     gScreenAddr = StripAddress(GetPixBaseAddr(mainScreenPixMap));    // make non-32bit friendly
  125.     gScreenRowBytes = (long)(0x7FFF&(**mainScreenPixMap).rowBytes);    // calc screen's rowBytes
  126.  
  127.  
  128.             /* MAKE A GIANT WINDOW TO COVER ENTIRE SCREEN */
  129.  
  130.     screenRect = qd.screenBits.bounds;                                // get screen's RECT
  131.     bigWindow = NewCWindow(nil,&screenRect,nil,true,
  132.                         plainDBox,(WindowPtr)-1L,false,0L);
  133. }
  134.  
  135.  
  136. /**************** INIT DRAW BUFFER ***************/
  137. //
  138. // Creates an offscreen draw buffer which we will
  139. // be blitting to the main screen.
  140. // The buffer is 640x480 8 bit pixels.
  141. //
  142.  
  143. static void InitDrawBuffer(void)
  144. {
  145.     gDrawBufferPtr = NewPtr(640*480);            // allocate the buffer
  146. }
  147.  
  148. /************************************************************/
  149. /******************** PROGRAM MAIN ENTRY  *******************/
  150. /************************************************************/
  151. //
  152. // WARNING: Make sure your monitor is set to 256 colors before
  153. //            running this!  Bad things may happen otherwise!
  154. //
  155.  
  156. void main(void)
  157. {
  158.             /* DO SETUP STUFF */
  159.             
  160.     ToolBoxInit();
  161.      InitScreen();
  162.      InitDrawBuffer();
  163.      
  164.              /* PROFILE IT */
  165.              
  166.      ProfileIt();
  167.  
  168.     ShowMenuBar();                        // restore menu bar
  169.     ExitToShell();                        // bye, bye!
  170. }
  171.  
  172.  
  173.  
  174.